package com.augurit.gzcgwsp.state.service.impl;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.NumberFormats;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.excelimportexport.util.ExcelUtil;
import com.augurit.gzcgwsp.excelimportexport.util.FileUtil;
import com.augurit.gzcgwsp.excelimportexport.util.GetFileName;
import com.augurit.gzcgwsp.state.dao.YwynpfStateDao;
import com.augurit.gzcgwsp.state.service.IYwYnpfStateService;
import com.augurit.gzcgwsp.state.web.form.YwYnPfStateForm;
import com.augurit.wf.common.dao.Jbpm4HistTaskDao;

/**
 * 余泥行政许可审批查询统计service实现类
 * 
 * @author 张军
 * 
 */
@Service
@Transactional
public class YwYnpfStateServiceImpl implements IYwYnpfStateService {
	private Logger log = Logger.getLogger(YwYnpfStateServiceImpl.class);

	@Autowired
	private YwynpfStateDao ywynpfStateDao;
	@Autowired
	private Jbpm4HistTaskDao jbpm4HistTaskDao;	

	/**
	 *减免sql
	 * @param map
	 * @return
	 */
	public String getSql(Map map){
		String sfjm = (String) map.get("sfjm");// 是否减免
		String keyword=(String)map.get("keyword");//关键字
		String startdate=(String) map.get("sqstartdate");
		String enddate=(String) map.get("sqdate");
		String gjz=(String) map.get("gjz");//关键字
		
		String gcmc=(String) map.get("gcmc");//工程名称
		String gclb=(String) map.get("gclb");//工程类别		
		String zsbh=(String) map.get("zsbh");//证件号码
		//证件流水号
		String acceptNo=(String) map.get("acceptNo");//受理号
		String gcdz=(String) map.get("gcdz");//工程地址
		String jsdwGz=(String) map.get("jsdwGz");//建设单位
		String sgdwGz=(String) map.get("sgdwGz");//施工单位
		String zslb=(String) map.get("zslb");//证书类别
		String tflStart=(String) map.get("tflStart");//土方量--开始
		String tflEnd=(String) map.get("tflEnd");//土方量--开始
		String area=(String) map.get("area");//区域
		String jmfe=(String) map.get("jmfe");//减免份额
		//证件状态
		String gdzk=(String) map.get("gdzk");//工地状况
		String sqDateStart=(String) map.get("sqDateStart");//申请日期--开始
		String sqDateEnd=(String) map.get("sqDateEnd");//申请日期--开始
		String sfje=(String) map.get("sfje");//收费状态
		System.out.println("sfje = "+sfje);
		String yxrqStart=(String) map.get("yxrqStart");//有效日期--开始
		String yxrqEnd=(String) map.get("yxrqEnd");//有效日期--开始
		String fzrqStart=(String) map.get("fzrqStart");//发证日期--开始
		String fzrqEnd=(String) map.get("fzrqEnd");//发证日期--开始
		String sql = " select  t.zsksrq,t.zsjsrq,t.sfje,t.ACCEPT_NO,t.gcmc,t.gcdz,t.sqdw,t.jsdw_gz,t.sgdw_gz,s.fz,t.sq_date,t.ysgs_kgrq,t.ysgs_wgrq,t.zsbh,  \r" +
				" s.ztf,s.zje,ins.bus_memo2, t.NEED_SQJMFQFK,\r" +
				"jht.execution_,jht.activity_name,jht.activity_chinese_name activity_chinese_name,jht.state_,ins.wf_bus_instance_id  from YW_YN_JZFQWCZC_PFSN t,\r" +
				"YW_YN_JZFQWCZC_CS s,WF_BUS_INSTANCE ins,JBPM4_HIST_TASK jht,\r" +
				"(select max(jhts.dbid_) maxdbid,jhts.execution_ from JBPM4_HIST_TASK jhts,WF_BUS_INSTANCE inss where jhts.execution_ = inss.proc_inst_id group by jhts.execution_) maxjht \r" +
				" where t.csid=s.id and ins.proc_inst_id=jht.execution_ and ins.proc_inst_id = jht.execution_ and jht.dbid_=maxjht.maxdbid \r";
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = sf.format(new Date());
		if(StringUtils.isNotBlank(sfje) && "已交齐".equals(sfje)){
			sql += " and t.sfje is not null";
		}else if(StringUtils.isNotBlank(sfje) && "未交".equals(sfje)){
			sql += " and t.sfje is null";
		}
		if(StringUtils.isNotBlank(gdzk)){
			sql += " and t.zsksrq <= to_date('"+dateStr+"', 'yyyy-MM-dd')";
			sql += " and t.zsjsrq >= to_date('"+dateStr+"', 'yyyy-MM-dd')";
		}
		if(StringUtils.isNotBlank(fzrqStart)){
			sql += " and t.fzrq >= to_date('"+fzrqStart+"', 'yyyy-MM-dd')";
		}
		if(StringUtils.isNotBlank(fzrqEnd)){
			sql += " and t.fzrq <= to_date('"+fzrqEnd+"', 'yyyy-MM-dd')";
		}
		if(StringUtils.isNotBlank(zsbh)){
			sql += " and t.zsbh like '%"+zsbh+"%'";
		}
		if(StringUtils.isNotBlank(yxrqStart)){
			sql += " and to_date(REPLACE(REPLACE(REPLACE(t.ysgs_wgrq,'日',''),'年','-'),'月','-'), 'yyyy-mm-dd') >= to_date('"+yxrqStart+"', 'yyyy-MM-dd')";
		}
		if(StringUtils.isNotBlank(yxrqEnd)){
			sql += " and to_date(REPLACE(REPLACE(REPLACE(t.ysgs_wgrq,'日',''),'年','-'),'月','-'), 'yyyy-mm-dd') <= to_date('"+yxrqEnd+"', 'yyyy-MM-dd')";
		}
		if(StringUtils.isNotBlank(sqDateStart)){
			sql += " and t.sq_date >= to_date('"+sqDateStart+"', 'yyyy-MM-dd')";
		}
		if(StringUtils.isNotBlank(sqDateEnd)){
			sql += " and t.sq_date <= to_date('"+sqDateEnd+"', 'yyyy-MM-dd')";
		}
		if(StringUtils.isNotBlank(tflStart)){
			sql += " and s.ztf >="+tflStart;
		}
		if(StringUtils.isNotBlank(tflEnd)){
			sql += " and s.ztf <="+tflEnd;
		}
		if(StringUtils.isNotBlank(gcmc)){
			sql += " and t.gcmc like '%"+gcmc+"%'";
		}
		if(StringUtils.isNotBlank(gclb) && !gclb.contains("所有")){
			sql += " and t.gclb = '"+gclb+"'";
		}
		if(StringUtils.isNotBlank(zslb) && !zslb.contains("所有")){
			sql += " and s.fz = '"+zslb+"'";
		}
		if(StringUtils.isNotBlank(sgdwGz)){
			sql += " and t.sgdw_gz like '%"+sgdwGz+"%'";
		}
		if(StringUtils.isNotBlank(jsdwGz)){
			sql += " and t.jsdw_Gz like '%"+jsdwGz+"%'";
		}
		if(StringUtils.isNotBlank(gcdz)){
			sql += " and t.gcdz like '%"+gcdz+"%'";
		}
		if(StringUtils.isNotBlank(acceptNo)){
			sql += " and t.ACCEPT_NO like '%"+acceptNo+"%'";
		}
		if(StringUtils.isNotBlank(gjz)){
			sql += " and (t.gcmc like '%"+gjz+"%' or t.gcdz like '%"+gjz+"%' or t.jsdw_gz like '%"+gjz+"%')";
		}
		if ("1".equals(sfjm)) {
			sql += " and t.NEED_SQJMFQFK='1'";
		}else if("2".equals(sfjm)){
			sql += " and t.NEED_SQJMFQFK is null";
		}
		if(StringUtils.isNotBlank(keyword)){
			sql += " and (t.gcmc like '%"+keyword+"%' " +
					"or t.gcdz like '%"+keyword+"%'" +
					" or t.gcdz like '%"+keyword+"%' or t.sqdw like '%"+keyword+"%' )";
		}
		if(StringUtils.isNotBlank(startdate)){
			startdate=startdate.substring(0,10);
			sql += " and t.sq_date >=to_date('"+startdate+"','yyyy-MM-dd')";
		}/*else{
			sql += " and t.sq_date >=to_date('"+year+"-01-01','yyyy-MM-dd')";
		}*/
		if(StringUtils.isNotBlank(enddate)){
			enddate=enddate.substring(0,10);
			sql += " and t.sq_date <=to_date('"+enddate+"','yyyy-MM-dd')";
		}/*else{
			sql += " and t.sq_date <=to_date('"+year+"-12-31','yyyy-MM-dd')";
		}*/
		if(StringUtils.isNotBlank(area) && !area.contains("所有") && !"市城管委".equals(area)){
			sql += " and  ins.bus_memo2='" + area + "'";
		}else if("市城管委".equals(area)){
			sql += " and  ins.bus_memo2 is null";
		}
		
		if("1".equals(jmfe)){//全免
			sql+=" and t.jmfe='1'";
		}else if("2".equals(jmfe)){//减一半
			sql+=" and t.jmfe='2'";
		}
		sql += " and t.accept_no=ins.bus_memo3";
		System.out.println("sql222 = "+sql);
		return sql;
	}
	/**
	 * 分页查询
	 */
	public Page search(Page page, Map map) {
		String sql=this.getSql(map);
		// List list=this.ywXzXkSpStateDao.searchByPage(sql, page, map);
		page = this.ywynpfStateDao.findPage(sql, page, map);
		// 转换page
		List<YwYnPfStateForm> list = convertFormList(page.getResult());
		page.setResult(list);
		return page;

	}

	/**
	 * 转换form排放工地和减免情况一起转换
	 * 
	 * @param result
	 * @param map
	 * @return
	 */
	private List<YwYnPfStateForm> convertFormList(List list) {
		List<YwYnPfStateForm> datas=new ArrayList<YwYnPfStateForm> ();
		if (list != null && list.size() > 0) {
			
			for (int k = 0; k < list.size(); k++) {
				Map map = (Map) list.get(k);
				String acceptNo = (String) map.get("accept_no");
				String ysdw=(String) map.get("ysgs")==null?"":(String) map.get("ysgs");// 运输单位
				String gcmc=(String) map.get("gcmc")==null?"":(String) map.get("gcmc");// 工程名称
				String gcdz = (String) map.get("gcdz")==null?"":(String) map.get("gcdz");// 工程地址
				String jsdw = (String) map.get("sqdw")==null?"":(String) map.get("sqdw");// 建设单位
				String zsbh = (String) map.get("zsbh")==null?"":(String) map.get("zsbh");// 证书编号
				String sgdw = (String) map.get("sgdw_gz")==null?"":(String) map.get("sgdw_gz");// 施工单位
				String lxr = (String) map.get("sgdw_lxr")==null?"":(String) map.get("sgdw_lxr");// 联系人
				String xmjl = (String) map.get("sgdw_xmjl")==null?"":(String) map.get("sgdw_xmjl");// 项目经理
				String start = (String) map.get("ysgs_kgrq")==null?"":(String) map.get("ysgs_kgrq");// 有效日期
				String end = (String) map.get("ysgs_wgrq")==null?"":(String) map.get("ysgs_wgrq");//有效日期
				String sqDate = (String) map.get("sq_date")==null?"":(String) map.get("sq_date");//申请日期
				String state = (String) map.get("activity_chinese_name")==null?"":(String) map.get("activity_chinese_name");//环节中午名称
				String state_ = (String) map.get("state_")==null?"":(String) map.get("state_");//状态
				String activity_name = (String) map.get("activity_name")==null?"":(String) map.get("activity_name");//环节英文名称				
				if(StringUtils.isNotBlank(state_) && "open".equals(state_) && !activity_name.contains("cksa")){//查上一环节
					String execution_ = (String) map.get("execution_")==null?"":(String) map.get("execution_");//工作流ID
					state = this.getPreState(execution_);
				}
				String fz = (String) map.get("fz");// 证书类别s
				String area = (String) map.get("bus_memo2")==null?"":(String) map.get("bus_memo2");//区域
				String sfje = (String) map.get("sfje")==null?"":(String) map.get("sfje");//收费金额
				
				String zslb="";
				if("1".equals(fz)){
					zslb="排放证";
				}else{
					zslb="临时余泥土渣排放复函";
				}
				String tfl=(String) map.get("ztf")==null?"0":(String) map.get("ztf");//
				String ffje=(String) map.get("zje")==null?"0":(String) map.get("zje");// 金额
				String sfjm=(String) map.get("need_sqjmfqfk")==null?"0":(String) map.get("need_sqjmfqfk");// 是否减免
				String fzrq=(String) map.get("fzrq")==null?"":(String) map.get("fzrq");// 发证日期
				String jmfe=(String) map.get("jmfe")==null?"0":(String) map.get("jmfe");// 减免份额

				String zsksrqStr= (String) map.get("zsksrq")==null?"":(String) map.get("zsksrq");//证书开始日期
				String zsjsrqStr = (String) map.get("zsjsrq")==null?"":(String) map.get("zsjsrq");//证书结束日期
				String wfBusInstanceId = (String) map.get("wf_bus_instance_id")==null?"":(String) map.get("wf_bus_instance_id");//WF_BUS_INSTANCE表的ID
				double jmje=0;
				if(StringUtils.isNotBlank(sfjm)){
					if("2".equals(jmfe)){
						jmje=Double.valueOf(ffje)*0.5;
					}else{
						jmje=Double.valueOf(ffje);
					}
				}
				YwYnPfStateForm form = null;
				form = new YwYnPfStateForm();
				form.setAcceptNo(acceptNo);
				form.setJsdw(jsdw);
				form.setFzrq(fzrq);
				form.setTfl(Integer.valueOf(tfl));
				form.setGcdz(gcdz);
				form.setYsdw(ysdw);
				form.setGcmc(gcmc);
				form.setZsbh(zsbh);
				form.setJmje(jmje);
				form.setZslb(zslb);
				form.setSgdw(sgdw);
				form.setLxr(lxr);
				form.setXmjl(xmjl);
//				form.setYxrq(start+"至"+end);
				form.setYxrq(end);
				if(StringUtils.isNotBlank(area)){
					form.setArea(area);
				}else{
					form.setArea("市城管委");
				}
				if(StringUtils.isNotBlank(sqDate)){
					SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
					try {
						form.setSqDate(sf.parse(sqDate));
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if(StringUtils.isNotBlank(sfje)){
					form.setSfje("已交齐");
				}else{
					form.setSfje("未交");
				}
				if(StringUtils.isNotBlank(zsksrqStr) && StringUtils.isNotBlank(zsjsrqStr)){
					SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
					try {
							
						String dateStr = sf.format(new Date());
						Date zsksrq = sf.parse(zsksrqStr);
						Date zsjsrq = sf.parse(zsjsrqStr);
						Date date = sf.parse(dateStr);
						if(date.getTime() >= zsksrq.getTime() && date.getTime() <= zsjsrq.getTime()){
							form.setGdzk("正在排放(受纳)");
						}
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				form.setState(state);
				form.setWfBusInstanceId(wfBusInstanceId);
				datas.add(form);
				
			}
	}
		return datas;
	}
	/**
	 * 获得上一环节节点名称
	 * @param execution_
	 * @return
	 */
	private String getPreState(String execution_){
		String sql = "select c.activity_chinese_name from JBPM4_HIST_TASK c ," +
		"(select max(a.dbid_) dbid from JBPM4_HIST_TASK a where a.execution_='"+execution_+"' and a.state_='completed') bb"+
		" where c.dbid_=bb.dbid";
		SQLQuery query = jbpm4HistTaskDao.getSession().createSQLQuery(sql);
		List list = query.list();
		if(list != null && list.size()>0){
			String str = (String)list.get(0);
			System.out.println("str = "+str);
			return str;
		}
		return null;
	}
	
	

	
	private String getPfSql(Map map){
		String area=(String)map.get("area");//关键字
		String startdate=(String) map.get("sqstartdate");
		String enddate=(String) map.get("sqdate");
		String yxstartdate=(String) map.get("startdate");
		String yxenddate=(String) map.get("endate");
		String year=DateUtilsEX.getCurYear();
		String sql = " select t.gcmc,t.gcdz,t.jsdw_gz, \r" +
		" t.zsbh,t.ysgs,t.sgdw_gz,t.sgdw_lxr,t.sgdw_xmjl,t.ysgs_kgrq " +
		", t.ysgs_wgrq,ins.wf_bus_instance_id from YW_YN_JZFQWCZC_PFSN t,WF_BUS_INSTANCE ins where ins.master_entity_key=t.id \r" +
		" and ins.master_entity='YwYnJzfqwczzPfsn' and t.ysgs_kgrq is not null";
			if(StringUtils.isNotBlank(area) && !"市城管委".equals(area)){
				sql+=" and ins.bus_memo2='"+area+"'";
			}else if("市城管委".equals(area)){
				sql+=" and ins.bus_memo2 is null";
			}
			if(StringUtils.isNotBlank(startdate)){
				startdate=startdate.substring(0,10);
				sql += " and t.sq_date >=to_date('"+startdate+"','yyyy-MM-dd')";
			}else{
				sql += " and t.sq_date >=to_date('"+year+"-01-01','yyyy-MM-dd')";
			}
			if(StringUtils.isNotBlank(enddate)){
				enddate=enddate.substring(0,10);
				sql += " and t.sq_date <=to_date('"+enddate+"','yyyy-MM-dd')";
			}else{
				sql += " and t.sq_date <=to_date('"+year+"-12-31','yyyy-MM-dd')";
			}
			if(StringUtils.isNotBlank(yxstartdate)){
				yxstartdate=yxstartdate.substring(0,10);
				sql += " and t.ysgs_kgrq >=to_date('"+yxstartdate+"','yyyy-MM-dd')";
			}
			
			if(StringUtils.isNotBlank(yxenddate)){
				yxenddate=yxenddate.substring(0,10);
				sql += " and t.ysgs_wgrq <=to_date('"+yxenddate+"','yyyy-MM-dd')";
			}
			return sql;
	}
	/**
	 * 正在排放统计
	 */
	@Override
	public Page searchPfData(Page page, Map map) {
		String sql=this.getPfSql(map);
		System.out.println("sql11 = "+sql);
		page = this.ywynpfStateDao.findPage(sql, page, map);
		// 转换page
		List<YwYnPfStateForm> list = convertFormList(page.getResult());
		page.setResult(list);
		return page;
	}

	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.state.service.IYwYnpfStateService#exportState(java.util.Map)
	 */
	@Override
	public String exportState(Map map) {
		String path = (String) map.get("contextpath");
		String outFilePath = GetFileName.GetRealPath("Templates/modelTemplate",
				"xls");
		String outPath = path + File.separator + outFilePath;
		outPath = outPath.replace("/", File.separator);
		String dir = outPath.substring(0, outPath.lastIndexOf(File.separator));
		dir = dir.replace("/", File.separator);
		File dirfile = new File(dir);
		if (!dirfile.exists()) {
			dirfile.mkdirs();
		}
		String inFilePath = path + File.separator + "Templates"
				+ File.separator + "exportPfStateData.xls";
		outPath = outPath.replace("/", File.separator);
		String sql=this.getPfSql(map);
		List list = this.ywynpfStateDao.queryForList(sql);
		writeData(inFilePath, outPath, list, map);
		String filename = outPath.substring(
				outPath.lastIndexOf(File.separator) + 1, outPath.length());
		try {// 删除其他文件
			FileUtil.delDir(dir, filename);
		} catch (IOException e) {
			log.error("删除文件错误" + e);
		}
		return outFilePath;
	}
	
	
	/**
	 * 写入查询数据
	 * 
	 * @param inFilePath
	 * @param outFilePath
	 * @param list
	 */
	private void writeData(String inFilePath, String outFilePath, List list,
			Map params) {
		WritableWorkbook wwb;
		try {
			wwb = ExcelUtil.createWorkbookByOld(inFilePath, outFilePath);
			WritableSheet ws = ExcelUtil.getWritableSheetByIndex(wwb, 0);
			WritableFont font = new WritableFont(WritableFont.createFont("宋体"),
					12);
			WritableCellFormat wcf = new WritableCellFormat(font,
					NumberFormats.TEXT);
			wcf.setBorder(Border.ALL, BorderLineStyle.THIN);
			wcf.setAlignment(Alignment.LEFT);
			wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
			wcf.setWrap(true);
			for (int i = 0; i < list.size(); i++) {
				List<YwYnPfStateForm> datas = this.convertFormList(list);
				try {
					int num=0;
					for (YwYnPfStateForm form : datas) {
						String gcmc = form.getGcmc();
						String gcdz=form.getGcdz();
						String zsbh=form.getZsbh();
						String jsdw=form.getJsdw();
						String ysdw=form.getYsdw();
						String sgdw=form.getSgdw();
						String lxr=form.getLxr();
						String xmjl=form.getXmjl();
						String yxrq=form.getYxrq();
						ExcelUtil.modiStrCell2(ws, 0, i + 2, String.valueOf(num), wcf);// 
						ExcelUtil.modiStrCell2(ws, 1, i + 2, gcmc, wcf);// 
						ExcelUtil.modiStrCell2(ws, 2, i + 2, gcdz, wcf);//
						ExcelUtil.modiStrCell2(ws, 3, i + 2, jsdw, wcf);//
						ExcelUtil.modiStrCell2(ws, 4, i + 2, ysdw, wcf);//
						ExcelUtil.modiStrCell2(ws, 5, i + 2, sgdw, wcf);//
						ExcelUtil.modiStrCell2(ws, 6, i + 2, lxr, wcf);//
						ExcelUtil.modiStrCell2(ws, 7, i + 2, xmjl, wcf);//
						ExcelUtil.modiStrCell2(ws, 8, i + 2, yxrq, wcf);//
						num++;
						ws.setRowView(i + 2, 600);
						i++;
					}
				} catch (Exception e) {
					log.error("导出数据错误" + e);
				}

			}
			wwb.write();
			wwb.close();
		} catch (Exception e) {

		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.state.service.IYwYnpfStateService#exportProjectData(java.util.Map)
	 */
	@Override
	public String exportProjectData(Map map) {
		String path = (String) map.get("contextpath");
		String outFilePath = GetFileName.GetRealPath("Templates/modelTemplate",
				"xls");
		String outPath = path + File.separator + outFilePath;
		outPath = outPath.replace("/", File.separator);
		String dir = outPath.substring(0, outPath.lastIndexOf(File.separator));
		dir = dir.replace("/", File.separator);
		File dirfile = new File(dir);
		if (!dirfile.exists()) {
			dirfile.mkdirs();
		}
		String inFilePath = path + File.separator + "Templates"
				+ File.separator + "exportPfProjectData.xls";
		outPath = outPath.replace("/", File.separator);
		map.put("sfjm", "1");
		String sql=this.getSql(map);
		List list = this.ywynpfStateDao.queryForList(sql);
		writeProjectData(inFilePath, outPath, list, map);
		String filename = outPath.substring(
				outPath.lastIndexOf(File.separator) + 1, outPath.length());
		try {// 删除其他文件
			FileUtil.delDir(dir, filename);
		} catch (IOException e) {
			log.error("删除文件错误" + e);
		}
		return outFilePath;
	}
	/**
	 * 写入查询数据
	 * @param inFilePath
	 * @param outFilePath
	 * @param list
	 */
	private void writeProjectData(String inFilePath, String outFilePath, List list,
			Map params) {
		WritableWorkbook wwb;
		try {
			wwb = ExcelUtil.createWorkbookByOld(inFilePath, outFilePath);
			WritableSheet ws = ExcelUtil.getWritableSheetByIndex(wwb, 0);
			WritableFont font = new WritableFont(WritableFont.createFont("宋体"),
					12);
			WritableCellFormat wcf = new WritableCellFormat(font,
					NumberFormats.TEXT);
			wcf.setBorder(Border.ALL, BorderLineStyle.THIN);
			wcf.setAlignment(Alignment.LEFT);
			wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
			wcf.setWrap(true);
			for (int i = 0; i < list.size(); i++) {
				List<YwYnPfStateForm> datas = this.convertFormList(list);
				try {
					int num=0;
					for (YwYnPfStateForm form : datas) {
						String acceptNo = form.getAcceptNo();
						String gcmc=form.getGcmc();
						String gcdz=form.getGcdz();
						String zsbh=form.getZsbh();
						String jsdw=form.getJsdw();
						String zslb=form.getZslb();
						int tfl=form.getTfl();
						String fzrq=form.getFzrq();
						double jmje=form.getJmje();
						ExcelUtil.modiStrCell2(ws, 0, i + 2, acceptNo, wcf);// 
						
						ExcelUtil.modiStrCell2(ws, 1, i + 2, gcmc, wcf);// 
						ExcelUtil.modiStrCell2(ws, 2, i + 2, gcdz, wcf);//
						ExcelUtil.modiStrCell2(ws, 3, i + 2, jsdw, wcf);//
						ExcelUtil.modiStrCell2(ws, 4, i + 2, zsbh, wcf);//
						ExcelUtil.modiStrCell2(ws, 5, i + 2, zslb, wcf);//
						ExcelUtil.modiStrCell2(ws, 6, i + 2, tfl+"", wcf);//
						ExcelUtil.modiStrCell2(ws, 7, i + 2, fzrq, wcf);//
						ExcelUtil.modiStrCell2(ws, 8, i + 2, jmje+"", wcf);//
						num++;
						ws.setRowView(i + 2, 600);
						i++;
					}
				} catch (Exception e) {
					log.error("导出数据错误" + e);
				}

			}
			wwb.write();
			wwb.close();
		} catch (Exception e) {

		}
	}
	
	
	@Override
	public Page searchJmProjectDatas(Page page, Map map) {
		map.put("sfjm", "1");//减免的工程
		String sql=this.getSql(map);
		// List list=this.ywXzXkSpStateDao.searchByPage(sql, page, map);
		page = this.ywynpfStateDao.findPage(sql, page, map);
		// 转换page
		List<YwYnPfStateForm> list = convertFormList(page.getResult());
		page.setResult(list);
		return page;
	}

}
